/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.service.impl;

import org.springblade.core.log.exception.ServiceException;
import org.springblade.modules.admin.entity.PlanScoreDimensionItem;
import org.springblade.modules.admin.vo.PlanScoreDimensionItemVO;
import org.springblade.modules.admin.mapper.PlanScoreDimensionItemMapper;
import org.springblade.modules.admin.service.IPlanScoreDimensionItemService;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 评分维度细项表 服务实现类
 *
 * @author ysq
 * @since 2024-01-15
 */
@Service
public class PlanScoreDimensionItemServiceImpl extends BaseServiceImpl<PlanScoreDimensionItemMapper, PlanScoreDimensionItem> implements IPlanScoreDimensionItemService {

	@Override
	public IPage<PlanScoreDimensionItemVO> selectPlanScoreDimensionItemPage(IPage<PlanScoreDimensionItemVO> page, PlanScoreDimensionItemVO planScoreDimensionItem) {
		return page.setRecords(baseMapper.selectPlanScoreDimensionItemPage(page, planScoreDimensionItem));
	}

	@Override
	public boolean customDeleteLogic(List<Long> ids) {
		List<PlanScoreDimensionItem> planScoreDimensionItems = this.listByIds(ids);
		long checkCount = planScoreDimensionItems.stream().filter(t -> t.getRequired() == 1).count();
		if (checkCount > 0) {
			throw new ServiceException("删除失败，无法删除默认数据!");
		}
		return deleteLogic(ids);
	}
}
